//
// Created by Martin on 2021/10/29.
//

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
#include <vector>

#define N_MAX 1000
#define C_MAX 10000
#define Q_MAX 200000

using namespace std;

int main()
{
    int N, c, x, Q;
    scanf("%d", &N);
    if (N < 1 || N > N_MAX)
    {
        printf("invalid N = %d\n", N);
        exit(1);
    }

    bitset<N_MAX + 1> *ps = new bitset<N_MAX + 1>[C_MAX];
    for (int i = 1; i <= N; ++i) {
        scanf("%d", &c);
        while (c--) {
            scanf("%d", &x);
            ps[x].set(i);
        }
    }

    int v1, v2;
    scanf("%d", &Q);
    while (Q--) {
        scanf("%d%d", &v1, &v2);
        if ((ps[v1] & ps[v2]).count())
            printf("Yes\n");
        else
            printf("No\n");
    }

    delete[] ps;
    return 0;
}
